package cn.com.inossem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.com.inossem.base.RequestActivity;
import cn.com.inossem.requestmanager.WooRequestFactory;
import cn.com.inossem.utils.ActivityStackControlUtil;

import com.foxykeep.datadroid.requestmanager.Request;

/**
 * 
 * 举报
 * 
 * <p>
 * detailed comment
 * 
 * @author szc 2015-8-24
 * @see
 * @since 1.0
 */
public class JuBaoActivity extends RequestActivity {

	CheckBox cb_guanggao, cb_seqing, cb_weifa, cb_shenfen, cb_qita;
	String reportType = "";
	TextView submit;
	EditText edittext;
	String gossipID = "";
	ImageView back;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.main_tab_layout);
		gossipID = getIntent().getStringExtra("gossipID");
		initView();

	}

	@Override
	public void onDestroy() {
		ActivityStackControlUtil.remove(this);
		super.onDestroy();
	}

	private void initView() {
		back = (ImageView) this.findViewById(R.id.back);
		back.setOnClickListener(this);
		submit = (TextView) this.findViewById(R.id.submit);
		submit.setOnClickListener(this);
		edittext = (EditText) this.findViewById(R.id.edittext);
		cb_guanggao = (CheckBox) this.findViewById(R.id.cb_guanggao);
		cb_guanggao.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				if (arg1) {
					cb_seqing.setChecked(false);
					cb_weifa.setChecked(false);
					cb_shenfen.setChecked(false);
					cb_qita.setChecked(false);
					reportType = "13232";
				} else {
					reportType = "";
				}
			}
		});

		cb_seqing = (CheckBox) this.findViewById(R.id.cb_seqing);
		cb_seqing.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				if (arg1) {
					cb_guanggao.setChecked(false);
					cb_weifa.setChecked(false);
					cb_shenfen.setChecked(false);
					cb_qita.setChecked(false);
					reportType = "13233";
				} else {
					reportType = "";
				}
			}
		});
		cb_weifa = (CheckBox) this.findViewById(R.id.cb_weifa);
		cb_weifa.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				if (arg1) {
					cb_guanggao.setChecked(false);
					cb_seqing.setChecked(false);
					cb_shenfen.setChecked(false);
					cb_qita.setChecked(false);
					reportType = "13234";
				} else {
					reportType = "";
				}
			}
		});
		cb_shenfen = (CheckBox) this.findViewById(R.id.cb_shenfen);
		cb_shenfen.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				if (arg1) {
					cb_guanggao.setChecked(false);
					cb_seqing.setChecked(false);
					cb_weifa.setChecked(false);
					cb_qita.setChecked(false);
					reportType = "13235";
				} else {
					reportType = "";
				}
			}
		});
		cb_qita = (CheckBox) this.findViewById(R.id.cb_qita);
		cb_qita.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				// TODO Auto-generated method stub
				if (arg1) {
					cb_guanggao.setChecked(false);
					cb_seqing.setChecked(false);
					cb_weifa.setChecked(false);
					cb_shenfen.setChecked(false);
					reportType = "13236";
				} else {
					reportType = "";
				}
			}
		});
	}

	public void checkclose() {
		cb_guanggao.setChecked(false);
		cb_seqing.setChecked(false);
		cb_weifa.setChecked(false);
		cb_shenfen.setChecked(false);
		cb_qita.setChecked(false);
	}

	@Override
	public Request getInitialRequest() {
		return null;

	}

	@Override
	public void onRequestSucess(Request request, Bundle bundle) {
		if (bundle.containsKey(WooRequestFactory.BUNDLE_EXTRA_UPDATESUCCESS)) {
			if (bundle.getInt(WooRequestFactory.BUNDLE_EXTRA_UPDATESUCCESS) == 1) {
				Toast.makeText(this, "举报成功！", Toast.LENGTH_LONG).show();
				finish();
			} else {
				Toast.makeText(this, "举报失败！", Toast.LENGTH_LONG).show();
			}
		}
	}

	@Override
	public void onRequestError(int exceptionType) {

	}

	public int getContentViewId() {
		return R.layout.jubao_layout;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.submit:
			if (!reportType.equals("")) {
				launchRequest(WooRequestFactory.jubao(gossipID, reportType,
						edittext.getText().toString()));
			} else {
				Toast.makeText(this, "必须选择一个！", Toast.LENGTH_LONG).show();
			}
			break;
		default:
			break;
		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (resultCode) { // resultCode为回传的标记，我在B中回传的是RESULT_OK
		case 1:
			setResult(1);
			finish();
		default:
			break;
		}
	}
}
